clear all
//set maxvar 120000
cd "C:\Users\mrabier\Dropbox\JOLE WARN Act\analysis/data/built"
use "cps_built_final_sample.dta", clear
cd "C:\Users\mrabier\Dropbox\JOLE WARN Act\analysis/output/"


drop if ONETHIRDWAIVER == 0 & PLANTCLOSING == 0 & EVENTUALTREAT == 1


********************************************************
*Table OA.12 LARF - Plant Closures only
*********************************************************

keep if PLANTCLOSING == 1

* Define covariates
local INDEPVAR FULLTIME UNION YEARS HI MARITAL EDUC AGE DWWEEKLLOG NCHILDBIN GDPPERCAPITA UNEMPRATE EMPPOP 

* Generate instrument

probit POSTTREAT `INDEPVAR' i.DWOCC1990 
predict PRED
gen KAPPA = 1-(NOTICELEN*(1-POSTTREAT))/(1-PRED) - ((1-NOTICELEN)*(POSTTREAT))/(PRED)

*---------------------------*
* WITH CONTROLS — NO LOOP  *
*---------------------------*
capture erase larf_controls.tex
cd "C:\Users\mrabier\Dropbox\JOLE WARN Act\analysis/output/"

* JOBLESS
reg JOBLESS NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum JOBLESS if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_plant.tex, replace keep(NOTICELEN) ctitle(Jobless) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons

* JOBLESSGT1WK
reg JOBLESSGT1WK NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum JOBLESSGT1WK if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_plant.tex, append keep(NOTICELEN) ctitle(Jobless > 1 wk) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons

* DWWKSUN
reg DWWKSUN NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum DWWKSUN if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_plant.tex, append keep(NOTICELEN) ctitle(Weeks Unemployed) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons

* CUREMP
reg CUREMP NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum CUREMP if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_plant.tex, append keep(NOTICELEN) ctitle(Currently Employed) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons

* FTtoPT
reg FTtoPT NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum FTtoPT if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_plant.tex, append keep(NOTICELEN) ctitle(Full to Part-time) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons
	
* DWWEEKCLOG
reg DWWEEKCLOG NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum FTtoPT if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_plant.tex, append keep(NOTICELEN) ctitle(Log (Current Earnings)) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons
	
	
********************************************************
*Table OA.11 LARF - Mass Layoffs only
*********************************************************	
	
clear all
//set maxvar 120000
cd "C:\Users\mrabier\Dropbox\JOLE WARN Act\analysis/data/built"
use "cps_built_final_sample.dta", clear
cd "C:\Users\mrabier\Dropbox\JOLE WARN Act\analysis/output/"


drop if ONETHIRDWAIVER == 0 & PLANTCLOSING == 0 & EVENTUALTREAT == 1

keep if PLANTCLOSING == 0

* Define covariates
local INDEPVAR FULLTIME UNION YEARS HI MARITAL EDUC AGE DWWEEKLLOG NCHILDBIN GDPPERCAPITA UNEMPRATE EMPPOP 

* Generate instrument

probit POSTTREAT `INDEPVAR' i.DWOCC1990 
predict PRED
gen KAPPA = 1-(NOTICELEN*(1-POSTTREAT))/(1-PRED) - ((1-NOTICELEN)*(POSTTREAT))/(PRED)

*---------------------------*
* WITH CONTROLS — NO LOOP  *
*---------------------------*
capture erase larf_controls.tex
cd "C:\Users\mrabier\Dropbox\JOLE WARN Act\analysis/output/"

* JOBLESS
reg JOBLESS NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum JOBLESS if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_mass.tex, replace keep(NOTICELEN) ctitle(Jobless) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons

* JOBLESSGT1WK
reg JOBLESSGT1WK NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum JOBLESSGT1WK if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_mass.tex, append keep(NOTICELEN) ctitle(Jobless > 1 wk) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons

* DWWKSUN
reg DWWKSUN NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum DWWKSUN if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_mass.tex, append keep(NOTICELEN) ctitle(Weeks Unemployed) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons

* CUREMP
reg CUREMP NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum CUREMP if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_mass.tex, append keep(NOTICELEN) ctitle(Currently Employed) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons

* FTtoPT
reg FTtoPT NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum FTtoPT if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_mass.tex, append keep(NOTICELEN) ctitle(Full to Part-time) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons
	
* DWWEEKCLOG
reg DWWEEKCLOG NOTICELEN `INDEPVAR' i.STATEFIP i.LOSSYEAR i.DWOCC1990 [iweight = KAPPA], vce(cluster STATEFIP)
boottest NOTICELEN, cluster(STATEFIP) reps(999) seed(12345)
scalar wild_t = r(t)
scalar wild_p = r(p)
sum FTtoPT if e(sample)
local mymean : di %8.2fc r(mean)
outreg2 using larf_mass.tex, append keep(NOTICELEN) ctitle(Log (Current Earnings)) ///
    addtext(Controls, Y, Year State Occ FE, Y, Dep. Var. Mean, `mymean', Wild t, `=wild_t', Wild p, `=wild_p') label nonotes nocons	
	
	
	
**************************************************
*Table OA.8 Effect of State WARN on Receipt and Length of Advance Notice
**************************************************
clear all
//set maxvar 120000
cd "C:\Users\mrabier\Dropbox\JOLE WARN Act\analysis/data/built"
use "cps_built_final_sample.dta", clear
cd "C:\Users\mrabier\Dropbox\JOLE WARN Act\analysis/output/"


drop if ONETHIRDWAIVER == 0 & PLANTCLOSING == 0 & EVENTUALTREAT == 1

* Clear previous stored estimates
eststo clear

* Define your variable list
local indepvars POSTTREAT FULLTIME UNION YEARS HI MARITAL EDUC AGE DWWEEKLLOG NCHILDBIN GDPPERCAPITA UNEMPRATE EMPPOP i.DWOCC1990 i.STATEFIP i.LOSSYEAR

* Run first regression
reg NOTICEBIN `indepvars', vce(cluster STATEFIP)
eststo noticebin
boottest POSTTREAT, cluster(STATEFIP) seed(12345) weighttype(webb) reps(9999) ptype(equaltail) jk
estadd scalar wild_p = r(p)
esttab noticebin, scalars(wild_p)

* Run second regression
reg NOTICELEN `indepvars', vce(cluster STATEFIP)
eststo noticelen
boottest POSTTREAT, cluster(STATEFIP) seed(12345) weighttype(webb) reps(9999) ptype(equaltail) jk
estadd scalar wild_p = r(p)

* Run third regression
reg NOTICEORD `indepvars', vce(cluster STATEFIP)
eststo noticeord
boottest POSTTREAT, cluster(STATEFIP) seed(12345) weighttype(webb) reps(9999) ptype(equaltail) jk
estadd scalar wild_p = r(p)


	
* Export results to RTF file with wild bootstrap p-values and SEs
esttab noticebin noticelen noticeord using results_table.tex, ///
    title("Effect of POSTTREAT on Notice Outcomes") ///
    b(3) se(3) star(* 0.10 ** 0.05 *** 0.01) ///
    drop(*.STATEFIP *.LOSSYEAR *.DWOCC1990) ///
    stats(N r2 wild_p, labels("Observations" "R-squared" "Wild p-value") ///
          fmt(0 3 3)) ///
    scalar(wild_p) ///
    addnote("All models include State, Year, and Occupation fixed effects") ///
    replace
